import json
import os
import re
import string

from collections import ChainMap

# Load JSON
dirname = os.path.dirname(os.path.abspath(__file__))
filename = os.path.join(dirname, 'words_dictionary.json')
with open(filename) as f:
    data = json.load(f)

# Reverse Dictionary for use when converting Anglo-Saxon -> Modern
reverse = dict([(value, key) for key, value in data.items()]) # Removes punctuation in input

# Group the 2 Dictionaries via a ChainMap
cm = ChainMap(data, reverse)

punctuation = re.compile(r"[^\W]+|[\.]")
userInput = punctuation.findall(input("Insert Phrase Here: \n").lower())

# Main loop
print(" ".join(cm.get(word, word) for word in userInput))
